import { getOgrTree } from '@/api/common'
const system = {
  state: {
    currentPage: null, // 代表当前活动页面
    commonOperations: [], // 用户的快捷方式
    orgTree: null // 用户能访问的单位树

  },

  mutations: {
    SET_CURRENTPAGE: (state, currentPage) => {
      state.currentPage = currentPage
    },
    SET_ORGTREE: (state, orgTree) => {
      state.orgTree = orgTree
    },
    SET_COMMONOPERATIONS: (state, commonOperations) => {
      state.commonOperations = commonOperations
    }

  },
  actions: {
    setCurrentPage({ commit }, currentPage) {
      commit('SET_CURRENTPAGE', currentPage)
    },
    setOrgTree({ commit }) {
      return new Promise((resolve, reject) => {
        getOgrTree().then(response => {
          const orgTree = response.data.data
          commit('SET_ORGTREE', orgTree)
          resolve()
        }).catch(error => {
          reject(error)
        })
      })
    },
    setCommonOperations({ commit }, commonOperations) {
      if (commonOperations) {
        commit('SET_COMMONOPERATIONS', commonOperations)
      }
    }

  }
}

export default system
